Page({
	data: {
		markers: [],
		latitude: '',
		longitude: '',
		placeData: {},
		xb:0
	},
	onLoad: function() {
		let that = this
		wx.getLocation({
			success: (res) => {
				let lngs = res.longitude
				let lats = res.latitude
				wx.request({
					url: getApp().globalData.xc,
					method: "POST",
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					data: {
						HTTP_API: 'vv/station/api/index/submit_search',
						lat: lats,
						lng: lngs,
						title: ''
					},
					success: (e) => {
						console.log(e)
						let marker = []
						e.data.data.list.forEach(function(item, index) {
							let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
							let x = item.lng;
							let y = item.lat;
							let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
							let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
							let lngs = z * Math.cos(theta) + 0.0065;
							let lats = z * Math.sin(theta) + 0.006;
							let a = String(item.juli).split('.')[0] / 1000
							if(a>1){
								a=String(a).slice(0, 5)+'km'
							}else{
								a=a*1000
								a=String(a).slice(0, 3)+'m'
							}
							marker.push(
								{
								 'iconPath': "../../img/wxz.png",
								 'id': index,
								'latitude': item.lat,
								'longitude': item.lng ,
								'width': 50,
								'height': 50,
								'juli':a,
								}
							)
							marker[0].iconPath='../../img/xz.png'
							item.lng = lngs
							item.lat = lats
							console.log(item)
						})
						console.log(e.data.data.list)
						that.setData({
							marker:marker,
							lng: lngs,
							lat: lats,
							list: e.data.data.list
						});
					}
				})
			}
		})

	},
	clickcontrol(e) {
	     let mpCtx = wx.createMapContext("map");
	    mpCtx.moveToLocation();
	  },
	makertap(e){
		console.log(e)
		let a=this.data.marker
		a[this.data.xb].iconPath="../../img/wxz.png"
		a[e.markerId].iconPath="../../img/xz.png"
		this.setData({
			xb:e.markerId,
			marker:a
		})
	}
})
